/*******************    (C) COPYRIGHT SUNSHINE SILICON    **********************
* \file
* File Name: config.h
* \brief
* Description:

    app_config
    
*  Copyright (C) 2014-2035 Sunshine Silicon Corporation (www.sunsili.com), All Rights Reserved
*  SPDX-License-Identifier: Apache-2.0
*
*  Licensed under the Apache License, Version 2.0 (the "License"); you may
*  not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
*  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*
*  This file is part of HS6200 sdk
*
* Version && Reversed History
* Version    Date       Auther      Reversed History
  ----------------------------------------------------------------------------
  V1.0.0    2021-07-07  Lojam Fan  Fisrt Created 
  
  (C) Sunshine Silicon Corporation (www.sunsili.com)
*******************************************************************************/


#ifndef __CONFIG_H__
#define __CONFIG_H__


#define MCU_STM8S

//#define MCU_N76E003
//#define MCU_C8051F380
//#define MCU_STC12C5A60
#define USE_SOFT_SPI
//#define USE_HW_SPI



#ifdef  MCU_STC12C5A60
//#include <reg52.h>
#include "stc12c5a60s2.h"

#elif defined MCU_N76E003
#define FOSC_160000
#include "N76E003.h"
#include "Common.h"
#include "Delay.h"
#include "SFR_Macro.h"
#include "Function_Define.h"

#elif defined MCU_STM8S
#include "stm8s.h"
#include "stm8s_gpio.h"

#endif

#ifdef USE_SOFT_SPI
#include "soft_spi.h"

#if defined (MCU_STC12C5A60) || defined (MCU_N76E003) 
sbit HS6200_CE = P1^0;
sbit HS6200_CS = P1^1;
sbit SCK = P1^2;
sbit MOSI = P1^3;
sbit MISO = P1^4; 

#define setGPIO_SPI_CE_OUT()    P10_PushPull_Mode
#define setGPIO_SPI_CS_OUT()    P11_PushPull_Mode
#define setGPIO_SPI_SCK_OUT()   P12_PushPull_Mode
#define setGPIO_SPI_MOSI_OUT()  P13_PushPull_Mode
#define setGPIO_SPI_MISO_IN()   P14_Input_Mode
#define	HS6200_CSN_HIGH()		HS6200_CS = 0x01 
#define	HS6200_CSN_LOW()		HS6200_CS = 0x00 
#define SPI_SCK_HIGH()          SCK = 1
#define SPI_SCK_LOW()           SCK = 0
#define SPI_MOSI_HIGH()         MOSI = 1
#define SPI_MOSI_LOW()          MOSI = 0
#define getGPIO(GPIOx)          (GPIOx)

#elif defined MCU_STM8S
#define SPI_CE      GPIOA, GPIO_PIN_2       
#define SPI_CS      GPIOA, GPIO_PIN_3
#define SPI_CLK     GPIOC, GPIO_PIN_5
#define SPI_MOSI    GPIOC, GPIO_PIN_6
#define SPI_MISO    GPIOC, GPIO_PIN_7
#define SPI_IRQ     GPIOA, GPIO_PIN_1       

#define setGPIO(GPIOx)  GPIO_WriteHigh(GPIOx)         
#define clrGPIO(GPIOx)  GPIO_WriteLow(GPIOx)         
#define getGPIO(GPIOx)  GPIO_ReadInputPin(GPIOx)    

#define setGPIO_SPI_CE_OUT()    GPIO_Init(SPI_CE,  GPIO_MODE_OUT_PP_HIGH_FAST)
#define setGPIO_SPI_CS_OUT()    GPIO_Init(SPI_CS,  GPIO_MODE_OUT_PP_HIGH_FAST)
#define setGPIO_SPI_SCK_OUT()   GPIO_Init(SPI_CLK,  GPIO_MODE_OUT_PP_HIGH_FAST)
#define setGPIO_SPI_MOSI_OUT()  GPIO_Init(SPI_MOSI, GPIO_MODE_OUT_PP_HIGH_FAST)
#define setGPIO_SPI_MISO_IN()   GPIO_Init(SPI_MISO, GPIO_MODE_IN_PU_NO_IT)
#define setGPIO_SPI_IRQ_IN()    GPIO_Init(SPI_IRQ, GPIO_MODE_IN_PU_NO_IT)
#define SPI_SCK_HIGH()          GPIO_WriteHigh(SPI_CLK)
#define SPI_SCK_LOW()           GPIO_WriteLow(SPI_CLK)
#define SPI_MOSI_HIGH()         GPIO_WriteHigh(SPI_MOSI)
#define SPI_MOSI_LOW()          GPIO_WriteLow(SPI_MOSI)
#define	HS6200_CSN_HIGH()		GPIO_WriteHigh(SPI_CS) 
#define	HS6200_CSN_LOW()		GPIO_WriteLow(SPI_CS) 
    

#endif

#elif defined (USE_HW_SPI) 

//------Hardware SPI define ----
#include "hw_spi.h"
//The next is need modify if new hardware fram
//#define	__HS6200_HARDWARE_SPI

#endif

#define	__HS6200_USE_CE_CTRL
#ifdef __HS6200_USE_CE_CTRL
#if defined (MCU_STC12C5A60) || defined (MCU_N76E003)  
#define	HS6200_CE_HIGH()	    HS6200_CE = 1	
#define	HS6200_CE_LOW()		    HS6200_CE = 0

#elif defined MCU_STM8S
#define HS6200_CE_HIGH()        GPIO_WriteHigh(SPI_CE)
#define HS6200_CE_LOW()         GPIO_WriteLow(SPI_CE)

#endif

#endif

#endif

/******************* (C) COPYRIGHT SUNSHINE SILICON  **************************
********************        END OF FILE config.h        *******************/